package com.kld.data.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.kld.common.annotation.Log;
import com.kld.common.core.controller.BaseController;
import com.kld.common.core.domain.PageQuery;
import com.kld.common.core.domain.R;
import com.kld.common.core.page.TableDataInfo;
import com.kld.common.enums.BusinessType;
import com.kld.data.domain.po.SysDruid;
import com.kld.data.service.ISysDruidService;
import com.kld.framework.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据连接Controller
 *
 * @author ruoyi
 * @date 2020-12-02
 */
@Validated
@Api(value = "数据源管理控制器", tags = {"数据源管理控制器"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/data/druid")
public class SysDruidController extends BaseController {

    private final ISysDruidService sysDruidService;

    /**
     * 查询数据连接列表
     */
    @SaCheckPermission("data:druid:list")
    @GetMapping("/list")
    public TableDataInfo list(SysDruid sysDruid, PageQuery pageQuery) {
        return sysDruidService.selectSysDruidList(sysDruid,pageQuery);
    }

    /**
     * 查询数据连接列表
     */
    @SaCheckPermission("data:druid:list")
    @GetMapping("/listAll")
    public List<SysDruid> listAll(SysDruid sysDruid) {
        return sysDruidService.selectSysDruidListAll(sysDruid);
    }


    /**
     * 获取数据连接详细信息
     */
    @SaCheckPermission("data:druid:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(sysDruidService.selectSysDruidById(id));
    }

    /**
     * 新增数据连接
     */
    @SaCheckPermission("data:druid:add")
    @Log(title = "数据连接", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@RequestBody SysDruid sysDruid) {
        return toAjax(sysDruidService.insertSysDruid(sysDruid));
    }

    /**
     * 修改数据连接
     */
    @SaCheckPermission("data:druid:edit")
    @Log(title = "数据连接", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody SysDruid sysDruid) {
        return toAjax(sysDruidService.updateSysDruid(sysDruid));
    }

    /**
     * 删除数据连接
     */
    @SaCheckPermission("data:druid:remove")
    @Log(title = "数据连接", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable String[] ids) {
        return toAjax(sysDruidService.deleteSysDruidByIds(ids));
    }
}
